package com.gadgets.framework.sysParam.service;

import com.gadgets.framework.common.constant.GadgetsExceptionConstant;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.PaginationUtil;
import com.gadgets.framework.sysParam.dto.SysParamQueryDTO;
import com.gadgets.framework.sysParam.dto.SysParamQueryResultDTO;
import com.gadgets.framework.sysParam.dto.SysParamUpdateDTO;
import com.gadgets.framework.sysParam.repository.ISysParamRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2021-07-19
 * @moduel gadgets
 *
 */
@Service
public class SysParammanageService implements ISysParamManageService{

    @Autowired
    private ISysParamRepository sysParamRepository;

    /**
     * 分页条件查询系统参数表信息
     *
     * @param queryDTO   查询条件
     * @param pagination 分页条件
     * @return 查询结果
     * @throws GadgetsServiceException 异常信息
     */
    @Override
    public List<SysParamQueryResultDTO> selectSysParamByConditionAndPagination(SysParamQueryDTO queryDTO, Pagination pagination) throws GadgetsServiceException {
        PaginationUtil.bulidPaginationInfo(pagination);
        List<SysParamQueryResultDTO> list =  sysParamRepository.selectSysParamByConditionAndPagination(queryDTO);
        PaginationUtil.getPaginationResultInfo(list,pagination);
        return list;
    }

    /**
     * 更新系统参数值
     *
     * @param updateDTO 更新信息
     * @throws GadgetsServiceException 异常信息
     */
    @Override
    public void updateSysParamValue(SysParamUpdateDTO updateDTO) throws GadgetsServiceException {
        int i = sysParamRepository.updateSysParamValue(updateDTO);
        if(i!=1){
            throw new GadgetsServiceException(GadgetsExceptionConstant.DATA_OPER_NUM_ERROR,1,i);
        }
    }

}
